# coding:utf-8

import json
import redis
import pymongo



def process_item():
    # 指定redis数据库
    rediscli = redis.Redis(host="127.0.0.1", port=6379, db=0)

    # 指定mongodb数据库
    mongocli = pymongo.MongoClient(host="127.0.0.1", port=27017)

    # 创建数据库
    db = mongocli["xiaoshuo"]
    # 创建表名
    sheet = db["frxxz"]

    while True:

        # FIFO模式为 blpop, LIFO模式为brpop 获取键值
        source , data = rediscli.blpop(["biquge:items"])
        print(" source --------->" + source)

        item = json.loads(data)
        sheet.insert(item)

        try:
            print(item)
        except KeyError:
            print(KeyError.message)




if __name__ == "__main__":
    process_item()